<template>
    <div class="checkout-total">
        <div class="totals">
            <table id="shopping-cart-totals-table">
                <tfoot>
                    <tr>
                        <td class="a-right">
                            <strong>Grand Total</strong>
                        </td>
                        <td class="a-right">
                            <strong>
                                <span class="price">{{grandTotal | Currency}}</span>
                            </strong>
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <tr>
                        <td class="a-right shopping-border">Subtotal</td>
                        <td class="a-right shopping-border">
                            <span class="price">{{subtotal | Currency}}</span>
                        </td>
                    </tr>
                    <tr v-if="couponCode<1">
                        <td class="a-right shopping-border">Discount（{{couponCodeText}}）</td>
                        <td class="a-right shopping-border">
                            <span class="price">- {{couponPrice | Currency}}</span>
                        </td>
                    </tr>
                    <tr>
                        <td class="a-right shopping-border">Shipping & Handling (USPS Expedited)</td>
                        <td class="a-right shopping-border">
                            <span class="price">+ {{shippingPrice | Currency}}</span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>
<script>
import mixin from '../../mixin'
export default {
    mixins: [mixin],
    props: {
        totalPrice: Number,
        shippingPrice: Number,
        couponCode: Number,
        couponCodeText: String
    },
    computed: {
        couponPrice() {
            if (this.couponCode < 1) {
                return (this.totalPrice * this.couponCode)
            }
        },
        grandTotal() {
            // 如果用优惠码
            if (this.couponCode < 1) {
                // 总价 - 折扣价 + 运费
                return (this.totalPrice - (this.totalPrice * this.couponCode) + this.shippingPrice)
            } else {
                // 总价 + 运费
                return (this.totalPrice + this.shippingPrice)
            }
        },
        subtotal() {
            return this.totalPrice
        }
    }
}
</script>